# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=pythran
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.13.1
pkgrel=2
pkgdesc="Ahead of Time compiler for numeric kernels (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://pythran.readthedocs.io/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-xsimd"
         "${MINGW_PACKAGE_PREFIX}-python-beniget"
         "${MINGW_PACKAGE_PREFIX}-python-gast"
         "${MINGW_PACKAGE_PREFIX}-python-ply"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip)
source=("https://pypi.python.org/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        001-fix-default-config.patch)
sha256sums=('8aad08162f010e5425a7b254dd68d83311b430bb29f9252dce2eff3ba39497dd'
            'aa03979a1ede62e1ea19d17eeaa3208afa4ddfa89bc0f70435dca41be7f8730f')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-default-config.patch

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  rm -r "$pkgdir"${MINGW_PREFIX}/lib/python*/site-packages/pythran/{boost,xsimd} # Remove bundled boost and xsimd

  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
